In this part, two maps were produced with QGIS and RStudio seperately. They are displayed here with brief descriptions about the procedures of making the maps, as well as a critical comparison of the tools used to produce them.
This a map showing the the percentage of people not born in London of each Borough with deeper blue indicating higher percentage.
Thematic map made with QGIS
The data was fetched from UK Data Services, with seperate london boundary shapefile and csv file of census data on population structure. To start making the map, add these two layers to QGIS through “Vector” tab and “Delimited Text” tab seperately in “Data Source Manager” accessed from the “Layer” menu.
Before joining two layers, check the attribute table of shapefile and the csv file to make sure there is a common field that can be set as the “join field”. Then the csv data was joined to the boundary shapefile by going to the “join” tab in the “properties” window of the boundary layer.
Next, display the data as desired through adjusting features under “Symbology” and “Label” tabs in the “properties” window of the boundary layer.
adjust labels
Base map was added through “XYZ Tiles”. To load the base map options, run the python script get from the tutorial online in the “Python Console” accessed from “Plugins” menu.
Lastly, the layout was generated using “Layout Manager”.
As shown in the “Data Source Manager”, QGIS is capable of compiling various types of data and adding them via different pathes. This makes it convenient to work together with all kinds of open sourse databases. Besides, various plugins including python console are supported, which gives it possibility to be conneted with resources and functions of other platforms.
While using QGIS to display the data, the result of visualization can be reflected immediately and adjusted accordingly to best convey the information. The color, style of lines, and style of text are directly demonstrated before being chosen to be applied to the map. Besides, it is intuitive to generate layout in a GUI-based tool because there is nested functions of adding different cartographical elements and they can be easily adjusted and moved around for the desired consequence.
Below are codes demonstrating the steps of building up an interactive map of the same theme and similar rendering style using the same data files and made with the Leaflet package in RStudio.
library(tidyverse)
## -- Attaching packages --------------------------------------- tidyverse 1.2.1 --
## v ggplot2 3.0.0 v purrr 0.2.5
## v tibble 1.4.2 v dplyr 0.7.6
## v tidyr 0.8.1 v stringr 1.3.1
## v readr 1.1.1 v forcats 0.3.0
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(sp)
library(rgdal)
## rgdal: version: 1.3-6, (SVN revision 773)
## Geospatial Data Abstraction Library extensions to R successfully loaded
## Loaded GDAL runtime: GDAL 2.2.3, released 2017/11/20
## Path to GDAL shared files: C:/Users/alexy/Documents/R/win-library/3.5/rgdal/gdal
## GDAL binary built with GEOS: TRUE
## Loaded PROJ.4 runtime: Rel. 4.9.3, 15 August 2016, [PJ_VERSION: 493]
## Path to PROJ.4 shared files: C:/Users/alexy/Documents/R/win-library/3.5/rgdal/proj
## Linking to sp version: 1.3-1
library(leaflet)
library(htmltools)
library(RColorBrewer)
BoroughBd <- readOGR("C:/Users/alexy/Desktop/GIS/wk1/BoundaryDataEdinaCensus/england_lad_2011.shp")
## OGR data source with driver: ESRI Shapefile
## Source: "C:\Users\alexy\Desktop\GIS\wk1\BoundaryDataEdinaCensus\england_lad_2011.shp", layer: "england_lad_2011"
## with 33 features
## It has 4 fields
LondonData <- read.csv("C:/Users/alexy/Desktop/GIS/wk1/LondonData.csv")
LondonData <- read_csv("C:/Users/alexy/Desktop/GIS/wk1/LondonData.csv", na = "n/a")
## Parsed with column specification:
## cols(
## .default = col_double(),
## Ward_name = col_character(),
## Old_code = col_character(),
## code = col_character(),
## Population_2015 = col_integer(),
## Children_aged_0_15_2015 = col_integer(),
## Working_age_16_64_2015 = col_integer(),
## Older_people_aged_65plus_2015 = col_integer(),
## Median_Age_2013 = col_integer(),
## Number_Killed_or_Seriously_Injured_on_the_roads_2014 = col_integer(),
## In_employment_16_64_2011 = col_integer(),
## Number_of_jobs_in_area_2013 = col_integer(),
## Number_of_properties_sold_2014 = col_integer(),
## Number_of_Household_spaces_2011 = col_integer()
## )
## See spec(...) for full column specifications.
LondonData <- data.frame(LondonData)
LondonBoroughs <- LondonData[grep("^E09",LondonData[,3]),] # select rows of London Boroughs
LondonBoroughs <- LondonBoroughs[,c(3,16)] # select needed columns
LondonBoroughs <- LondonBoroughs[2:34,] # get rid of duplicated column
BoroughBd@data <- data.frame(BoroughBd@data,LondonBoroughs[match(BoroughBd@data[,"code"],LondonBoroughs[,"code"]),]) # join the attribute data to the SP data
names(BoroughBd)[3] <- c("Borough Name") # rename the column
## Warning in checkNames(value): attempt to set invalid names: this may lead
## to problems later on. See ?make.names
names(BoroughBd)[6] <- c("Percentage")
## Warning in checkNames(value): attempt to set invalid names: this may lead
## to problems later on. See ?make.names
BoroughBd <- BoroughBd[c(3,6)] # extract the two neccessary columns
Borough_repro <-spTransform(BoroughBd, CRS("+proj=longlat +datum=WGS84")) #reproject the data
map <- leaflet(Borough_repro)%>%setView(lng = 0, lat = 51.5, zoom = 9)
map%>%addProviderTiles(providers$Esri.WorldGrayCanvas)
bins <- c(10.3, 19.9, 31.0, 39.4, 48.2, 55.1)
pal <- colorBin(c("#f7fbff", "#c8ddf0","#73b3d8","#2879b9","#08306b"), domain = Borough_repro$Percentage, bins = bins)
map%>%addPolygons(weight = 1,
opacity = 1,
color = "#fff",
smoothFactor = 0.3,
fillOpacity = 1,
fillColor = ~pal(Percentage))
# UNSOLVED ISSUE: the grey background of this layer cannot be get rid of, which covers the basemap
map%>%addPolygons(weight = 1,opacity = 1, color = "#fff", smoothFactor = 0.3, fillOpacity = 1, fillColor = ~pal(Percentage),
highlight = highlightOptions(
weight = 5,
color = "#fff",
fillOpacity = 1,
bringToFront = TRUE))